package model

import (
	"example/initDB"
	"log"
)

type UserModel struct {
	Id            string
	Name          string `form:"name"`
	Password      string `form:"password"`
	PasswordAgain string `form:"passwordAgain"`
	Account       string `form:"account"`
}

func (user *UserModel) QueryByName() UserModel {
	u := UserModel{}
	row := initDB.Db.QueryRow("select account,password from hello.user where account = ?;", user.Account)
	e := row.Scan(&u.Account, &u.Password)
	if e != nil {
	}
	return u
}

func (user *UserModel) Save() int64 {
	res, e := initDB.Db.Exec("insert into hello.user (name, account, password) values (?, ?, ?);", user.Name, user.Account, user.Password)
	if e != nil {
	}
	id, err := res.LastInsertId()
	if err != nil {
		log.Panicln("admin insert id error", err.Error())
	}
	return id
}
